package interfaz;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.border.EmptyBorder;

public class Prueba extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Prueba frame = new Prueba();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Prueba() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		// Display an icon and a string for each object in the list.

		// Display an icon and a string for each object in the list.

		 class MyCellRenderer extends JLabel implements ListCellRenderer<Object> {
		     final ImageIcon longIcon = new ImageIcon("long.gif");
		     final ImageIcon shortIcon = new ImageIcon("short.gif");

		     // This is the only method defined by ListCellRenderer.
		     // We just reconfigure the JLabel each time we're called.

		     public Component getListCellRendererComponent(
		       JList<?> list,           // the list
		       Object value,            // value to display
		       int index,               // cell index
		       boolean isSelected,      // is the cell selected
		       boolean cellHasFocus)    // does the cell have focus
		     {
		         String s = value.toString();
		         setText(s);
		         setIcon((s.length() > 10) ? longIcon : shortIcon);
		         if (isSelected) {
		             setBackground(list.getSelectionBackground());
		             setForeground(list.getSelectionForeground());
		         } else {
		             setBackground(list.getBackground());
		             setForeground(list.getForeground());
		         }
		         setEnabled(list.isEnabled());
		         setFont(list.getFont());
		         setOpaque(true);
		         return this;
		     }
		 }

		
	}

}
